<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="waName">
        <el-input
          v-model="queryParams.waName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工号" prop="jobNum">
        <el-input
          v-model="queryParams.jobNum"
          placeholder="请输入工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前年月" prop="currentYm">
        <el-date-picker
          v-model="queryParams.currentYm"
          type="month"
          placeholder="选择当前年月">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hr:gzhs:add']"
        >核算工资
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hr:gzhs:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hr:gzhs:remove']"
        >反核算
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hr:gzhs:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gzhsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="姓名" align="center" prop="waName" />
      <el-table-column label="工号" align="center" prop="jobNum" width="140"/>
      <el-table-column label="部门" align="center" prop="department" />
      <el-table-column label="分部" align="center" prop="division" />
      <el-table-column label="组别" align="center" prop="waGroup" />
      <el-table-column label="岗位" align="center" prop="post" />
      <el-table-column label="入职日期" align="center" prop="entryTime" width="120"/>
      <el-table-column label="当前年月" align="center" prop="currentYm" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.currentYm, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实到天数" align="center" prop="actualDayNum" />
      <el-table-column label="实到小时" align="center" prop="actualHour" />
      <el-table-column label="休班天数" align="center" prop="restDayNum" />
      <el-table-column label="请假/天数" align="center" prop="leaveDayNum" />
      <el-table-column width="150" label="新到/离职差勤天数" align="center" prop="departureChaDayNum" />
      <el-table-column width="120" label="考勤计算基数" align="center" prop="attendCalBase" />
      <el-table-column width="120" label="本月应出勤天数" align="center" prop="ycqDayNum" />
      <el-table-column width="120" label="节假日出勤小时" align="center" prop="jjryqHours" />
      <el-table-column width="120" label="拖班/加班小时" align="center" prop="workOvertime" />
      <el-table-column width="120" label="拖班抵休班天数" align="center" prop="tbdxDayNum" />
      <el-table-column width="180" label="抵完休/假班后的拖班小时" align="center" prop="dxwTime" />
      <el-table-column label="加班/差勤" align="center" prop="jbType" />
      <el-table-column width="120" label="是否计算加班" align="center" prop="isJsjb" />
      <el-table-column label="工龄" align="center" prop="workAge" />
      <el-table-column label="岗位分类" align="center" prop="gwClassification" />
      <el-table-column label="是否转正" align="center" prop="isFormal" />
      <el-table-column label="基本工资" align="center" prop="baseWages" />
      <el-table-column label="绩效工资" align="center" prop="jxWages" />
      <el-table-column label="小时工资" align="center" prop="hourMoney" />
      <el-table-column width="120" label="岗位工资" align="center" prop="zrgwWages" />
      <el-table-column label="工资合计" align="center" prop="wagesTotal" />
      <el-table-column width="120" label="应发基本工资" align="center" prop="yfBasicWages" />
      <el-table-column width="150" label="应发岗位工资" align="center" prop="yfGwzrWages" />
      <el-table-column width="120" label="应发加班工资" align="center" prop="yfJbWages" />
      <el-table-column width="120" label="应发绩效工资" align="center" prop="yfJxWages" />
      <el-table-column width="140" label="月度工资（小时）" align="center" prop="hourMgz" />
      <el-table-column width="120" label="应发计件工资" align="center" prop="yfJjWages" />
      <el-table-column width="120" label="应发交通补贴" align="center" prop="yfJtWages" />
      <el-table-column width="120" label="应发通讯补贴" align="center" prop="yfTxWages" />
      <el-table-column label="全勤奖" align="center" prop="qqj" />
      <el-table-column label="学历补贴" align="center" prop="xlbt" />
      <el-table-column label="星级奖励" align="center" prop="xjjl" />
      <el-table-column label="其他补贴" align="center" prop="otherBt" />
      <el-table-column width="120" label="高温/取暖补贴" align="center" prop="gwbt" />
      <el-table-column label="特殊补贴" align="center" prop="specialBt" />
      <el-table-column label="餐卡" align="center" prop="ck" />
      <el-table-column label="餐补" align="center" prop="cb" />
      <el-table-column label="工作服等" align="center" prop="gzf" />
      <el-table-column width="120" label="应发工资合计" align="center" prop="yfWagesTotal" />
      <el-table-column label="保险" align="center" prop="insurance" />
      <el-table-column width="120" label="住房公积金" align="center" prop="zfgjj" />
      <el-table-column label="个税" align="center" prop="grsds" >
        <template slot-scope="scope">
          <el-button
            type="text"
            style="text-decoration: underline"
            @click="handleGsjs(scope.row)"
          >{{scope.row.grsds}}</el-button>
        </template>
      </el-table-column>
<!--      <el-table-column label="已发放" align="center" prop="yff" />-->
      <el-table-column width="120" label="工作服等扣款" align="center" prop="gzfkk" />
      <el-table-column label="其他扣款" align="center" prop="otherKk" />
      <el-table-column width="120" label="考核罚没款" align="center" prop="khfmj" />
      <el-table-column label="奖励工资" align="center" prop="reward" />
      <el-table-column width="120" label="实发工资合计" align="center" prop="actualWagesTotal" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hr:gzhs:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hr:gzhs:remove']"
          >反核算
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工资核算对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">

        <el-row>
          <el-col :span="8">
            <el-form-item label="公司代码" prop="factoryCode">
              <el-input v-model="form.factoryCode" placeholder="请输入公司代码" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公司名称" prop="factoryName">
              <el-input v-model="form.factoryName" placeholder="请输入公司名称" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="姓名" prop="waName">
              <el-input v-model="form.waName" placeholder="请输入姓名" readonly/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="工号" prop="jobNum">
              <el-input v-model="form.jobNum" placeholder="请输入工号" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="部门" prop="department">
              <el-input v-model="form.department" placeholder="请输入部门" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="分部" prop="division">
              <el-input v-model="form.division" placeholder="请输入分部" readonly/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="组别" prop="waGroup">
              <el-input v-model="form.waGroup" placeholder="请输入组别" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="岗位" prop="post">
              <el-input v-model="form.post" placeholder="请输入岗位" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当前年月" prop="currentYm">
              <el-date-picker clearable
                              v-model="form.currentYm"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="请选择当前年月">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="实到天数" prop="actualDayNum">
              <el-input v-model="form.actualDayNum" placeholder="请输入实到天数" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="休班天数" prop="restDayNum">
              <el-input v-model="form.restDayNum" placeholder="请输入休班天数" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="请假/天数" prop="leaveDayNum">
              <el-input v-model="form.leaveDayNum" placeholder="请输入请假/天数" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="新到/离职差勤天数" prop="departureChaDayNum">
              <el-input v-model="form.departureChaDayNum" placeholder="请输入新到/离职差勤天数"  :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="本月应出勤天数" prop="ycqDayNum">
              <el-input v-model="form.ycqDayNum" placeholder="请输入本月应出勤天数" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="节假日出勤小时" prop="jjryqHours">
              <el-input v-model="form.jjryqHours" placeholder="请输入节假日出勤小时" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="拖班/加班小时" prop="workOvertime">
              <el-input v-model="form.workOvertime" placeholder="请输入拖班/加班小时" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="拖班抵休班天数" prop="tbdxDayNum">
              <el-input v-model="form.tbdxDayNum" placeholder="请输入拖班抵休班天数" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="抵完休/假班后的拖班小时" prop="dxwTime">
              <el-input v-model="form.dxwTime" placeholder="请输入抵完休/假班后的拖班小时" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="是否计算加班" prop="isJsjb">
              <el-input v-model="form.isJsjb" placeholder="请输入是否计算加班" :readonly=this.extendState  />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入职时间" prop="entryTime">
              <el-date-picker clearable
                              v-model="form.entryTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择入职时间"
              readonly >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工龄" prop="workAge">
              <el-input v-model="form.workAge" placeholder="请输入工龄" readonly />
            </el-form-item>
          </el-col>
        </el-row>



        <el-row>
          <el-col :span="8">
            <el-form-item label="保险情况" prop="insurSituation">
              <el-input v-model="form.insurSituation" placeholder="请输入保险情况" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="岗位分类" prop="gwClassification">
              <el-input v-model="form.gwClassification" placeholder="请输入岗位分类" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否转正" prop="isFormal">
              <el-input v-model="form.isFormal" placeholder="请输入是否转正" readonly />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="基本工资" prop="baseWages">
              <el-input v-model="form.baseWages" placeholder="请输入基本工资" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="绩效工资" prop="jxWages">
              <el-input v-model="form.jxWages" placeholder="请输入绩效工资" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="岗位工资" prop="zrgwWages">
              <el-input v-model="form.zrgwWages" placeholder="请输入岗位工资" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="交通补贴" prop="jtbt">
              <el-input v-model="form.jtbt" placeholder="请输入交通补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="通讯补贴" prop="txbt">
              <el-input v-model="form.txbt" placeholder="请输入通讯补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工资合计" prop="wagesTotal">
              <el-input v-model="form.wagesTotal" placeholder="请输入工资合计" :readonly=this.extendState  />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="应发基本工资" prop="yfBasicWages">
              <el-input v-model="form.yfBasicWages" placeholder="请输入应发基本工资"  :readonly=this.yfBasicWagesState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应发岗位工资" prop="yfGwzrWages">
              <el-input v-model="form.yfGwzrWages" placeholder="请输入应发岗位工资" :readonly=this.yfBasicWagesState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应发加班工资" prop="yfJbWages">
              <el-input v-model="form.yfJbWages" placeholder="请输入应发加班工资" :readonly=this.yfBasicWagesState />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="应发计件工资" prop="yfJjWages">
              <el-input v-model="form.yfJjWages" placeholder="请输入应发计件工资" :readonly=this.yfBasicWagesState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应发交通补贴" prop="yfJtWages">
              <el-input v-model="form.yfJtWages" placeholder="请输入应发交通补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应发通讯补贴" prop="yfTxWages">
              <el-input v-model="form.yfTxWages" placeholder="请输入应发通讯补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="全勤奖" prop="qqj">
              <el-input v-model="form.qqj" placeholder="请输入全勤奖" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="学历补贴" prop="xlbt">
              <el-input v-model="form.xlbt" placeholder="请输入学历补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="星级奖励" prop="xjjl">
              <el-input v-model="form.xjjl" placeholder="请输入星级奖励" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="其他补贴" prop="otherBt">
              <el-input v-model="form.otherBt" placeholder="请输入其他补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="高温/取暖补贴" prop="gwbt">
              <el-input v-model="form.gwbt" placeholder="请输入高温/取暖补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="特殊补贴" prop="specialBt">
              <el-input v-model="form.specialBt" placeholder="请输入特殊补贴" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="餐卡" prop="ck">
              <el-input v-model="form.ck" placeholder="请输入餐卡" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="餐补" prop="cb">
              <el-input v-model="form.cb" placeholder="请输入餐补" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工作服等" prop="gzf">
              <el-input v-model="form.gzf" placeholder="请输入工作服等" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="应发工资合计" prop="yfWagesTotal">
              <el-input v-model="form.yfWagesTotal" placeholder="请输入应发工资合计" :readonly=this.yfBasicWagesState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="保险" prop="insurance">
              <el-input v-model="form.insurance" placeholder="请输入保险" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="住房公积金基数" prop="zfgjj">
              <el-input v-model="form.zfgjj" placeholder="请输入住房公积金基数" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="个税" prop="grsds">
              <el-input v-model="form.grsds" placeholder="请输入个税" :readonly=this.extendState />
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="已发放" prop="yff">-->
<!--              <el-input v-model="form.yff" placeholder="请输入已发放"/>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="8">
            <el-form-item label="工作服等扣款" prop="gzfkk">
              <el-input v-model="form.gzfkk" placeholder="请输入工作服等扣款" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="其他扣款" prop="otherKk">
              <el-input v-model="form.otherKk" placeholder="请输入其他扣款" :readonly=this.extendState />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="考核罚没款" prop="khfmj">
              <el-input v-model="form.khfmj" placeholder="请输入考核罚没款" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="奖励工资" prop="reward">
              <el-input v-model="form.reward" placeholder="请输入奖励工资" :readonly=this.extendState />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="实发工资合计" prop="actualWagesTotal">
              <el-input v-model="form.actualWagesTotal" placeholder="请输入实发工资合计" :readonly=this.yfBasicWagesState />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="选择年月" :visible.sync="currentOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="数据源" prop="sjly">
          <el-select v-model="form.sjly" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="月份" prop="ny">
          <el-date-picker clearable
                          v-model="form.ny"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择核算月份">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--  <div class="el-upload__tip" slot="tip">
              <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listGzhs, getGzhs, delGzhs, addGzhs, updateGzhs,gzhs} from "@/api/hr/gzhs";
import {getToken} from "@/utils/auth";

export default {
  name: "Gzhs",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工资核算表格数据
      gzhsList: [],
      options: [{
        value: '1',
        label: '人工考勤'
      }, {
        value: '2',
        label: '系统考勤'
      }],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      currentOpen: false,
      yfBasicWagesState:false,
      extendState:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryCode: null,
        factoryName: null,
        waName: null,
        jobNum: null,
        department: null,
        division: null,
        waGroup: null,
        post: null,
        currentYm: null,
        actualDayNum: null,
        restDayNum: null,
        leaveDayNum: null,
        departureChaDayNum: null,
        ycqDayNum: null,
        jjryqHours: null,
        workOvertime: null,
        tbdxDayNum: null,
        dxwTime: null,
        jbType: null,
        isJsjb: null,
        qnType: null,
        entryTime: null,
        workAge: null,
        insurSituation: null,
        gwClassification: null,
        isFormal: null,
        baseWages: null,
        jxWages: null,
        zrgwWages: null,
        jtbt: null,
        txbt: null,
        wagesTotal: null,
        yfBasicWages: null,
        yfGwzrWages: null,
        yfJbWages: null,
        yfJjWages: null,
        yfJtWages: null,
        yfTxWages: null,
        qqj: null,
        xlbt: null,
        xjjl: null,
        otherBt: null,
        gwbt: null,
        specialBt: null,
        ck: null,
        cb: null,
        gzf: null,
        yfWagesTotal: null,
        insurance: null,
        zfgjj: null,
        grsds: null,
        yff: null,
        gzfkk: null,
        otherKk: null,
        khfmj: null,
        reward: null,
        actualWagesTotal: null,
        waCardNum: null,
        openBank: null,
        userInfo: null,
        attendCalBase: null,
        isJx: null,
        hourMoney: null,
        jcWay: null,
        zmjbMoney: null,
        holidayMoney: null,
        actualHour: null
      },
      upload: {
        // 是否显示弹出层（物料导入）
        open: false,
        // 弹出层标题（物料导入）
        title: "导入`gzhs`信息",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/hr/gzhs/importData"
      },
      // 表单参数
      form: {
        ny:null,
        sjly:null
      },
      // 表单校验
      rules: {
        ny: [
          { required: true, trigger: "blur", message: "请选择月份" }
        ],
        sjly: [
          { required: true, trigger: "blur", message: "请选择数据源" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  activated(){
    this.getList();
  },
  methods: {
    /** 查询工资核算列表 */
    getList() {
      this.loading = true;
      listGzhs(this.queryParams).then(response => {
        this.gzhsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel2() {
      this.currentOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryCode: null,
        factoryName: null,
        waName: null,
        jobNum: null,
        department: null,
        division: null,
        waGroup: null,
        post: null,
        currentYm: null,
        actualDayNum: null,
        restDayNum: null,
        leaveDayNum: null,
        departureChaDayNum: null,
        ycqDayNum: null,
        jjryqHours: null,
        workOvertime: null,
        tbdxDayNum: null,
        dxwTime: null,
        jbType: null,
        isJsjb: null,
        qnType: null,
        entryTime: null,
        workAge: null,
        insurSituation: null,
        gwClassification: null,
        isFormal: null,
        baseWages: null,
        jxWages: null,
        zrgwWages: null,
        jtbt: null,
        txbt: null,
        wagesTotal: null,
        yfBasicWages: null,
        yfGwzrWages: null,
        yfJbWages: null,
        yfJjWages: null,
        yfJtWages: null,
        yfTxWages: null,
        qqj: null,
        xlbt: null,
        xjjl: null,
        otherBt: null,
        gwbt: null,
        specialBt: null,
        ck: null,
        cb: null,
        gzf: null,
        yfWagesTotal: null,
        insurance: null,
        zfgjj: null,
        grsds: null,
        yff: null,
        gzfkk: null,
        otherKk: null,
        khfmj: null,
        reward: null,
        actualWagesTotal: null,
        remark: null,
        waCardNum: null,
        openBank: null,
        userInfo: null,
        createTime: null,
        createBy: null,
        updateBy: null,
        updateTime: null,
        attendCalBase: null,
        isJx: null,
        hourMoney: null,
        jcWay: null,
        zmjbMoney: null,
        holidayMoney: null,
        actualHour: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd(){
      this.reset();
      this.currentOpen = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGzhs(id).then(response => {
        console.log(response.data);
        if(response.data.dataSource == '2'){
          this.yfBasicWagesState=true
        }else{
          this.yfBasicWagesState=false
        }
        if(response.data.dataSource == '1'){
          this.extendState=true
        }else{
          this.extendState=false
        }


        this.form = response.data;
        this.open = true;
        this.title = "修改工资核算";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGzhs(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGzhs(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    submitForm2() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: 'Loading',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          });
          gzhs(this.form.ny,this.form.sjly).then(response => {
            if(response.code==200){
              if(response.msg==='0'){
                this.$modal.msgWarning(this.form.ny+"无考勤数据！");
              }
              else if(response.msg === '-1'){
                this.$modal.msgWarning("请先设置薪酬设置的基本工资");
              }else{
                this.$modal.msgSuccess("核算完成");
              }
              this.currentOpen = false;
              this.getList();
            }
            loading.close();
          });
        }
      });

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除工资核算编号为"' + ids + '"的数据项？').then(function () {
        return delGzhs(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hr/gzhs/export', {
        ...this.queryParams
      }, `gzhs_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "工资核算导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('hr/gzhs/importTemplate', {}, `工资核算模板.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    handleGsjs(row){
      this.$router.push({path:'/hrsystem/xinzhouguanli/zsgl/gsjs',query:{jobNo : row.jobNum,ny:row.currentYm}})
    }
  }
};
</script>
